﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.BLL.NetBar;
using FortuneHeaven.Entity.NetBar;
using Jzy.Common;
using FortuneHeaven.BLL.Accounts;

namespace FortuneHeaven.Admin.Pages.NetBar
{
    public partial class Statistic : PageDetail
    {
        private int? _netBarID;
        private int NetBarID
        {
            get
            {
                if (_netBarID == null)
                {
                    UserExBO user = new UserExBO();
                    UserExInfo info = user.GetInfo(AppSession.UserID);
                    if (info != null)
                    {
                        _netBarID = info.NetBarID;
                    }
                    else
                    {
                        _netBarID = 0;
                    }
                }
                return _netBarID.Value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NetBarBO netBar = new NetBarBO();

                NetBarInfo netInfo = netBar.GetInfo(NetBarID);
                litNetbarName.Text = netInfo.NetbarName;
                litRemainScore.Text = netInfo.Score.ToString() ;
                litExperience.Text = netInfo.Experience.ToString();

                AccountsBO accounts = new AccountsBO();
                litRegisterCount.Text = accounts.GetRegisterCount(NetBarID).ToString();
                litTodayRegisterCount.Text = accounts.GetTodayRegisterCount(NetBarID,DateTime.Now).ToString();
                litAccountTotalScore.Text = accounts.GetTotalScore(NetBarID).ToString();
                litMemberCount.Text = accounts.GetMemberCount(NetBarID).ToString();

                ScoreHistoryBO scoreHistory = new ScoreHistoryBO();
                litTodayAddScore.Text = scoreHistory.GetTodayAddScore(NetBarID, DateTime.Now).ToString();

                litAddScoreTotal.Text = scoreHistory.GetTotalAddScore(NetBarID).ToString();

                litTodaySubScore.Text = (-scoreHistory.GetTodaySubScore(NetBarID, DateTime.Now)).ToString();
                litTotalSubScore.Text = (-scoreHistory.GetTotalSubScore(NetBarID)).ToString();

                litLoss.Text = (long.Parse(litAddScoreTotal.Text) - long.Parse(litAccountTotalScore.Text) - long.Parse(litTotalSubScore.Text)).ToString();
            }
        }
    }
}